package com.ljl.mvvmdemo.util

import androidx.appcompat.app.AppCompatActivity
import java.util.*

/**
 * activity栈
 * created by luojialun on 2024/4/10
 */
class ActivityUtils private constructor() {
    companion object {
        val instance: ActivityUtils by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            ActivityUtils()
        }
    }

    private var activityStack: Stack<AppCompatActivity> = Stack()

    fun addActivity(activity: AppCompatActivity) {
        activityStack.add(activity)
    }

    fun removeActivity(activity: AppCompatActivity) {
        activityStack.remove(activity)
    }

    fun getCurrentActivity(): AppCompatActivity {
        return activityStack.lastElement()
    }

}